package org.bggood.org.service.impl;

import org.bggood.basic.PageList;
import org.bggood.org.domain.Department;
import org.bggood.org.mapper.IDepartmentMapper;
import org.bggood.org.query.DepartmentQuery;
import org.bggood.org.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class DepartmentServiceImpl implements IDepartmentService {

    @Resource
    private IDepartmentMapper departmentMapper;

    @Override
    @Transactional
    public void add(Department department) {
        departmentMapper.insert(department);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        departmentMapper.delete(id);
    }

    @Override
    @Transactional
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Override
    public Department queryById(Long id) {
        return departmentMapper.loadById(id);
    }

    @Override
    public List<Department> queryAll() {
        return departmentMapper.loadAll();
    }

    @Override
    public PageList<Department> pageLoad(DepartmentQuery query) {
        Integer count = departmentMapper.count(query);
        List<Department> departments = departmentMapper.pageLoad(query);
        PageList<Department> pageList = new PageList<>();
        pageList.setRows(departments);
        pageList.setTotals(count);
        return pageList;
    }
}
